#include "stdafx.h"
#include "Profiler.h"

using namespace mcore;

_int64 Profiler::mAllTime = 0;
int Profiler::mNumSamples = 0;

Profiler::Profiler()
{
	start();
}


Profiler::~Profiler()
{
	stop();
}

void Profiler::start()
{
	unsigned int ui;
	mTime = __rdtscp(&ui);
}

void Profiler::stop()
{
	unsigned int ui;
	_int64 time = __rdtscp(&ui);
	mAllTime += time - mTime;
	mNumSamples++;
}

void Profiler::dump(const std::string & desc)
{
	static std::stringstream ss;
	ss.str("");
	ss << mAllTime / mNumSamples;
	LOG("PROFILING: " + desc + " " + ss.str());
}